<template>
  <div>
    <el-card style="margin-bottom: 20px">
      <el-form label-width="90px" :rules="rules" ref="statusRef" :model="evaluation">
        <el-form-item label="考评名称" style="margin-right: 100px" prop="name">
          <el-input placeholder="请输入考评名称" v-model="evaluation.name"></el-input>
        </el-form-item>
        <el-form-item label="考评指标">
          <el-select v-model="evaluation.templateId" placeholder="选择指标" style="margin-right: 5px">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="开关">
          <el-switch
              :disabled="disabled"
              v-model="evaluation.status"
              active-color="#13ce66"
              inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item>
          <div style="display: flex;justify-content: flex-end">
            <el-button type="primary" @click="addEvaluation">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-card>

    <el-card>
      <el-descriptions title="完成进度">
        <el-descriptions-item label="高校总数">{{status.gCount}}</el-descriptions-item>
        <el-descriptions-item label="中小学总数">{{status.zCount}}</el-descriptions-item>
        <el-descriptions-item label=""></el-descriptions-item>

        <el-descriptions-item label="已完成">{{status.gfinish}}</el-descriptions-item>
        <el-descriptions-item label="已完成">{{status.zfinish}}</el-descriptions-item>
      </el-descriptions>
      <div style="display: flex;justify-content: flex-end">
        <el-button type="danger">结束考评</el-button>
      </div>
    </el-card>

  </div>
</template>

<script>
import request from "@/urils/request";

export default {
  name: "Status",
  data() {
    return {
      value: false,
      values: '',
      options: [],
      evaluation: {
        name: '',
        templateId: '',
        status: 0
      },
      disabled: false,
      rules: {
        name: [
          {required: true, message: "名称不能为空", trigger: "blur"}
        ]
      },
      status: {}
    }
  },
  methods: {
    loadTemplate() {
      request.get('/criterion/templateList').then(res => {
        if (res.code === '200') {
          for (let i in res.data) {
            this.options.push({
              value: res.data[i].id,
              label: res.data[i].name
            })
          }
        }
      })
    },
    addEvaluation() {
      this.$refs['statusRef'].validate((valid) => {
        if (valid) {
          if (this.evaluation.templateId === '') {
            this.$message.error("未选择考评指标")
          } else {
            this.evaluation.status = this.evaluation.status ? 1 : 0
            request.post("/evaluation/add", this.evaluation).then(res => {
              if (res.code === '200') {
                this.$message.success("设置成功")
                if (this.evaluation.status) {
                  this.evaluation.status = true
                  this.disabled = true
                }
              } else {
                this.$message.error(res.msg)
              }
            })
          }
        } else {
          this.$message.error("未输入信息")
        }
      })
    },
    loadStatus() {
      request.get('/evaluation/getStatus').then(res => {
        if(res.code === '200'){
          this.status = res.data
          console.log(this.status)
        }else{
          this.$message.error(res.msg)
        }
      })
    }
  },
  created() {
    this.loadTemplate()
    this.loadStatus()
  }

}
</script>

<style scoped>

</style>